<template>
    <app>
        <el-form :model="form"  ref="form" label-position="left" label-width="0px" class="demo-ruleForm login-container">
            <h3 class="title">行车公寓乘务员就餐消费信息管理系统</h3>
            <el-form-item >
                <el-input type="text" v-model="form.username" auto-complete="off" placeholder="账号"></el-input>
            </el-form-item>
            <el-form-item >
                <el-input type="password" v-model="form.password" @keyup.enter.native="login" auto-complete="off" placeholder="密码"></el-input>
            </el-form-item>
            <el-form-item >
                <div>
                    <img :src="imgbase64" @click="getCodeImage">
                </div>
                <el-input type="text" style="width: 50%" v-model="form.code" @keyup.enter.native="login" auto-complete="off" placeholder="验证码"></el-input>

            </el-form-item>
            <el-form-item style="width:100%;">
                <el-button type="primary" style="width:100%;" @click="login" :loading="logining">登录</el-button>

            </el-form-item>
        </el-form>

    </app>
</template>

<script>
    //import { requestLogin } from '../api/api';
    //import NProgress from 'nprogress'

    export default {
        data() {
            return {
                logining: false,
                form: {
                    username: '888888',
                    password: '123456',
                    code:'',
                    codeUUID:""
                },
                imgbase64:"",

            };
        },
        methods: {
            login(){
                this.$api.login(this.form)
                .then(res=>{
                    if (res.code==200){
                        localStorage.setItem('token',res.data.token);

                        this.$router.push({path:'/home'})
                    }else {
                        this.$message.error(res.message);
                        this.getCodeImage();
                    }
                })
            },
            getCodeImage(){
                this.$api.getCodeImage()
                .then(res=>{
                    if (res.code==200){
                        this.imgbase64=res.data.image;
                        this.form.codeUUID=res.data.codeUUID;
                    }
                })
            }
        },
        mounted() {
            this.getCodeImage();
        }
    }
</script>

<style lang="scss" scoped>
    .login-container {
        /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
        -webkit-border-radius: 5px;
        border-radius: 5px;
        -moz-border-radius: 5px;
        background-clip: padding-box;
        margin: 180px auto;
        width: 350px;
        padding: 35px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;
        .title {
            margin: 0px auto 40px auto;
            text-align: center;
            color: #505458;
        }

    }
</style>